var productIdss = [];
var productQtyss = [];
$(function(){
    typeList();
    var product = $('#product').data('id').split('p');
    productIdss =  product[0].split('a')
    productQtyss = product[1].split('a');
    console.log(productIdss+":"+productQtyss)
})
function typeList(){
    var arr = {
        hf_s_id: 'WD11',
        hf_srv_id: 'Cv_jcus_shoplist',
        hs_action_id: 'get_list'
    }
    getAjaxRequest(arr,function(result){
       // alert(111)
       // if (result.bs_is_login == BS_IS_LOGIN.Y) {
            sessionStorage.setItem("typeId", result[0].bs_id);
            var htmllist = '<option value="">--Please select--</option>';
            var len = result.length;
            if (len > 0) {
                for (var i = 0; i < len; i++) {
                    htmllist += '<option value="' + result[i].bs_id + '">' + result[i].bs_value + '</option>';
                }
                $('#select-save-list').html(htmllist);
            } else {
                $('#select-save-list').html();
            }
       /* }else{
            var redirectUrl = encodeURI(location.href);
            location.href = MPJ.base + "/pages/login.jsp?redirectUrl="+redirectUrl;
        }*/
    })
}
var typeId = '';
function change(){
    typeId = $('#select-save-list option:selected').val();
}

$('.saveListBox a.mui-btn').on('tap',function(){
	/*dialog('Message', 'Product has been successfully added to <span style="color:#ef6e19;display:block;"> my favourite list </span>', 3);
    var $dialog = $('#dialog');*/
    var typeName = $('#listName').val();
/*    $dialog.show();
    $('.giveBtn').html('View list');
    $dialog.find('.comfirmBtn').one('click', function() {*/
        addCartList(typeId,typeName)
   /*     $dialog.hide();
        $dialog.remove();
    	$this.remove();
    });*/
})
//增加商品到购物清单
function addCartList(typeId,typeName){
    if(typeName=="" && typeId==""){
        dialog('Msessage', '请至少选择一项', 1);
        var $dialog = $('#dialog');
        $dialog.show();
        $dialog.find('.comfirmBtn').one('click', function() {
            $dialog.hide();
            $dialog.remove();
            mui('#offCanvasContentScroll').scroll().scrollTo(0,0,100);
        });
    }else{
        if('' != typeName){
            var lastUrl = '?hf_s_id=WD11&hf_srv_id=Cv_jcus_shoplist&hs_action_id=create_list&hs_list_name='+typeName;
        }
        if( '' != typeId){
            var lastUrl = '?hf_s_id=WD11&hf_srv_id=Cv_jcus_shoplist&hs_action_id=add_items_to_list&hs_list_id='+typeId;
        }

        for(var i = 0; i<productIdss.length-1; i++){
            lastUrl += '&hvs_pdt_id='+productIdss[i]+'&hvs_pdt_qty='+productQtyss[i];
        }
        var url = MPJ.apiUrl + lastUrl;
        getAjaxRequest({},function(result){
            location.href=MPJ.base+"/pages/account/shopping/list.jsp";
        },url);
    }
}